package gooner.suntine.ssh.eg.dao;

import gooner.suntine.ssh.eg.entity.Student;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


/**
 * @corporation 
 * @author suntine
 * @creation 2011-5-5 10:15:55 AM
 * @description 
 */
public class StudentDaoImpl extends HibernateDaoSupport implements StudentDao {
	
    //create
    public void save(Student student)
    {
        try {
			getHibernateTemplate().save(student);
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    //delete
    public void delete(Student student){
    	 try {
			this.getHibernateTemplate().delete(student);
		} catch (Exception e) {
			// TODO: handle exception
		}
    }
    
    public void deleteById(int id){
		 try {
			this.getHibernateTemplate().delete(
					getHibernateTemplate().get(Student.class, new Long(id)));
		} catch (Exception e) {
			// TODO: handle exception
		}
    }
    
    //read
    @SuppressWarnings("unchecked")
	public List<Student> queryByHql(String hql){
    		try {
				return (List<Student>) this.getHibernateTemplate().find(hql);
			} catch (Exception e) {
				// TODO: handle exception
				return null;
			}
    }
    
    public Student get(int id){
    	
    		try {
				return (Student) this.getHibernateTemplate().get(Student.class,
						new Long(id));
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				return null;
			}
    }
	
    //update
    public void update(Student student)
    {
        try {
			getHibernateTemplate().update(student);
		} catch (Exception e) {
			// TODO: handle exception
		}
    }
    
}
